public class LeetCode283 {

    public static void main(String[] args) {
//        moveZeroes3(new int[]{0,0,0,0,1});

        String s = "112";
        System.out.println(s.contains("1"));;
    }

    public void moveZeroes(int[] nums) {
//        for (int k: nums){
//            System.out.print(k + " ");
//        }
//        System.out.println();
        int zeroNum = 0;
        for (int i = 0; i < nums.length; i++){
            if (nums[i] == 0){
                zeroNum++;
//                System.out.println(true);
            }else{
//                System.out.println(false);
                if (zeroNum > 0){
                    nums[i - zeroNum] = nums[i];
                    nums[i] = 0;
                }

            }

//            for (int k: nums){
//                System.out.print(k + " ");
//
//            }
//            System.out.println();
        }

        for (int x: nums){
            System.out.print(x + " ");
        }
    }

    public void moveMethod2(int[] arr){
        if (arr == null || arr.length <= 0){
            return;
        }

        int j = 0;
        for (int i = 0; i < arr.length; i++){
            if (arr[i] != 0){
                arr[j] = arr[i];
                j++;
            }
        }

        for (int i = j; i < arr.length; i++){
            arr[i] = 0;
        }
    }

    public static void moveZeroes3(int[] nums) {
        int zeroIndex = -1;

        for (int i = 0; i < nums.length; i++){
            if(nums[i] == 0 && zeroIndex == -1){
                zeroIndex = i;
                continue;
            }
            if(nums[i] != 0 && zeroIndex != -1){
                nums[zeroIndex] = nums[i];
                nums[i] = 0;
                zeroIndex++;
            }
        }

        for (int num:nums){
            System.out.print(num + " ");
        }
        System.out.println();

    }
}
